package com.hdc.lw.controller;

import com.hdc.lw.po.Category;
import com.hdc.lw.service.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryServiceImpl categoryService;

    /**
     * 获取商品分类列表
     * @return
     */
    @RequestMapping("list")
    public Object findAllCategory() {
        return categoryService.findAllCategory();
    }

    /**
     * 添加商品分类
     * @param category
     * @return
     */
    @RequestMapping("add")
    public Object addCategory(@RequestBody Category category) {
        return categoryService.addCategory(category);
    }

    /**
     * 根据id删除商品分类
     * @param id
     * @return
     */
    @RequestMapping("delete/{id}")
    public Object deleteCategory(@PathVariable("id") Integer id) {
        return categoryService.deleteCategory(id);
    }

    /**
     * 更新商品分类
     * @param category
     * @return
     */
    @RequestMapping("update")
    public Object updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }
}
